package com.irdstudio.smcenter.agent.boot;

import java.sql.SQLException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;

import com.irdstudio.sdk.agents.enums.AgentModeEnum;
import com.irdstudio.sdk.agents.init.AgentInstInfo;
import com.irdstudio.sdk.agents.init.AgentResourceLoader;
import com.irdstudio.sdk.plugins.utils.SpringContextUtils;

/**
 * <p>Agent启动入口,根据属性文件中的参数分别支持dubbo,hsf及local模式的agent</p>
 * @author fuzm
 * @date 2018-06-15
 */
@SpringBootApplication
@ComponentScan(basePackages = {"com.irdstudio.smcenter"})
public class AgentApplicationBoot {
	
	/** 日志输出对象 */
	private static final Logger logger = LoggerFactory.getLogger(AgentApplicationBoot.class);

	public static void main(String[] args) throws SQLException {
		// 加载路径配置
		AgentResourceLoader.me().start();
		String agentMode = AgentInstInfo.AGENT_MODE;

		// 读取参数来确定Agent的启动模式
		if (AgentModeEnum.HSF.getCode().equals(agentMode)) {
			/*
			 * System.out.println("正在以agent for hsf模式启动..."); PandoraBootstrap.run(args);
			 * ApplicationContext context =
			 * SpringApplication.run(AgentApplicationBoot.class, args);
			 * SpringContextUtils.setApplicationContext(context); // 初始化hsf服务
			 * HsfServiceConfig.init(); test();
			 * 
			 * PandoraBootstrap.markStartupAndWait();
			 */
		} else if (AgentModeEnum.DUBBO.getCode().equals(agentMode)) {

			logger.info("正在以agent for dubbo模式启动...");
		} else {
			logger.info("正在以agent for local模式启动...");
			ApplicationContext context = SpringApplication.run(AgentApplicationBoot.class, args);
			SpringContextUtils.setApplicationContext(context);
		}
	}
}
